<?php
/**
 * 
 * @author HZ_02
 * 特价申报实体类
 */
class SaleAction extends CommonAction{
	
	public function index(){
		$model = M("Special");
		$user  = session(C('USER_AUTH_OBJECT'));
		if(IS_POST){
			if($model->create()){
				$model->solevar  = create_id();
				$model->addtime  = time();
				$model->outletid = $user['outletid'];
				
				$model->add();
				
				$this->assign("jumpUrl",U('Sale/index'));
				$this->success("特价申报成功，请等待系统审核！");
			}else{
				$this->error('特价申报失败，请稍后重试！');
			}
		}else{
			import('ORG.Util.Page');// 导入分页类
			$map['outletid'] = $user['outletid'];
			
			$count = $model->where($map)->count();// 查询满足要求的总记录数
			$Page  = new Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
			$show  = $Page->show();// 分页显示输出
			
			$data = $model->where($map)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('page',$show);// 赋值分页输出
			
			$empty="您暂时没有申报任何特价商品~！";
			$this->assign("empty",$empty);
			
			foreach($data as $k=>$v){
				$status_str = "";
				$status     = $v['status'];
				if($status==1)
					$status_str = "<span style='color:green'>审核通过</span>";
				elseif($status==2)
					$status_str = "待审核";
				else
					$status_str = "<span style='color:red'>审核不通过</span>";
				
				$data[$k]['status'] = $status_str;
			}
			
			$this->assign("data",$data);
			$this->display();
		}
	}
	
	public function detail(){
		$this->display();
	}
}
?>